// 猜你喜欢   轮播图

const carouselItems = document.querySelectorAll(
    '.home-panel .xtx-carousel .carousel-item'
  )
  const carouselItem = document.querySelector(
    '.home-panel .xtx-carousel .carousel-item'
  )
  const btnPrev = document.querySelector('.home-panel .xtx-carousel .prev')
  const btnNext = document.querySelector('.home-panel .xtx-carousel .next')

  let index = 0
  let clearFade = function () {
    for (let i = 0; i < carouselItems.length; i++) {
      carouselItems[i].className = 'carousel-item'
    }
  }
  let goIndex = function () {
    clearFade()
    carouselItems[index].className = 'carousel-item fade'
    document.querySelector('li.active').classList.remove('active')
    lis[index].classList.add('active')
  }
  
  let goNext = function () {
    index++
    if (index > 3) {
      index = 0
    }
    goIndex()
  }
  let goPrev = function () {
    index--
    if (index < 0) {
      index = 3
    }
    goIndex()
  }
  btnNext.addEventListener('click', function () {
    goNext()
  })
  btnPrev.addEventListener('click', function () {
    goPrev()
  })
  
  const lis = document.querySelectorAll('.carousel-indicator ol>li')
  for (let i = 0; i < lis.length; i++) {
    lis[i].addEventListener('click', function () {
      index = i
      goIndex()
    })
  }